//
//  CBCTopMenuView.m
//  CBCReader
//
//  Created by Labanotation on 16/6/1.
//  Copyright © 2016年 okwei. All rights reserved.
//

#import "CBCTopMenuView.h"
#import "CBCMenuView.h"
#import "CBCReadUtilites.h"
#import "CommonFuctions.h"

#if __has_include(<Masonry/Masonry.h>)
#import <Masonry/Masonry.h>
#else
#import "Masonry.h"
#endif
@interface CBCTopMenuView ()
@property (nonatomic,strong) UIButton *back;
@property (nonatomic,strong) UIButton *share;
@end
@implementation CBCTopMenuView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

-(void)setIsHiddenShare:(BOOL)isHiddenShare{
    _isHiddenShare = isHiddenShare;
    self.share.hidden = self.isHiddenShare;
}
-(void)setup
{
    [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.8]];
    [self addSubview:self.back];
    [self addSubview:self.share];
    [self.back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.bottom.equalTo(self).offset(-4);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    [self.share mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-10);
        make.bottom.equalTo(self.back);
        make.size.equalTo(self.back);
    }];
    
}

-(UIButton *)back
{
    if (!_back) {
        _back = [CBCReadUtilites commonButtonSEL:@selector(tapBack:) target:self];
        [_back setImage:[CommonFuctions cbcReaderImage:@"btn_back_white"] forState:UIControlStateNormal];
    }
    return _back;
}
-(UIButton *)share
{
    if (!_share) {
        _share = [CBCReadUtilites commonButtonSEL:@selector(tapShare:) target:self];
        [_share setImage:[CommonFuctions cbcReaderImage:@"btn_share_white"] forState:UIControlStateNormal];
    }
    return _share;
}
-(void)tapShare:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(menuViewShare:)]) {
        [self.delegate menuViewShare:self];
    }
}
-(void)tapBack:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(menuViewBack:)]) {
        [self.delegate menuViewBack:self];
    }
}

@end
